package cn.jbooter.session.autoconfigure;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionStrategy;

import cn.jbooter.session.autoconfigure.config.hash_map.SessionHashMapHttpSessionConfiguration;
import cn.jbooter.session.autoconfigure.config.redis.SessionRedisConnectionConfiguration;
import cn.jbooter.session.autoconfigure.config.redis.SessionRedisHttpSessionConfiguration;
import cn.jbooter.session.autoconfigure.properties.ISpringSessionProperties;



@Configuration
@ConditionalOnMissingBean(SessionRepository.class)
@ConditionalOnClass(Session.class)
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "spring.jsession", name="enabled", havingValue="true")
@EnableConfigurationProperties(ISpringSessionProperties.class)
@Import({
	SessionHashMapHttpSessionConfiguration.class,
	SessionRedisConnectionConfiguration.class,
	SessionRedisHttpSessionConfiguration.class
})
public class ISpringSessionAutoConfigure {
	
	/**
	 * restfull接口的session支持,需在header中添加头:x-auth-token
	 * @return
	 */
	@Bean
	@ConditionalOnProperty(prefix = "spring.jsession", name="rest-strategy", havingValue="true")
    public HttpSessionStrategy httpSessionStrategy() {
            return new HeaderHttpSessionStrategy();
    }
	

}
